package tr.edu.metu.is.mega.server.validation;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * Singleton validator utility class.
 */
public final class ValidationUtil {

    private static ValidationUtil instance = null;

    private Validator validator = null;

    /**
     * Hidden constructor.
     */
    private ValidationUtil() {
        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
        validator = factory.getValidator();
    }

    /**
     * Returns singleton instance of this.
     * 
     * @return singleton instance
     */
    public static ValidationUtil getInstance() {
        if (instance == null) {
            instance = new ValidationUtil();
        }
        return instance;
    }

    /**
     * Returns the validator.
     * 
     * @return the validator
     */
    public Validator getValidator() {
        return validator;
    }

}
